package com.frcdi.qms.web.controller.material;

import com.frcdi.qms.common.core.controller.BaseController;
import com.frcdi.qms.common.core.domain.AjaxResult;
import com.frcdi.qms.common.core.page.TableDataInfo;
import com.frcdi.qms.material.domain.Materials;
import com.frcdi.qms.material.service.MaterialService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName MaterialController
 * @Author Mr.Han
 * @Description //TODO $
 * @create 2024/7/8 17:42
 **/
@RestController
@RequestMapping("/materials")
public class MaterialHandler extends BaseController {
    @Autowired
    private MaterialService materialService;

    @PostMapping("/add")
    public AjaxResult addMaterial(@RequestBody Materials material) {
        materialService.addMaterial(material);
        return success("Material added successfully");
    }

    @PutMapping("/update")
    public AjaxResult updateMaterial(@RequestBody Materials material) {
        materialService.updateMaterial(material);
        return success("Material updated successfully");
    }

    @DeleteMapping("/delete/{id}")
    public AjaxResult deleteMaterial(@PathVariable Integer id) {
        materialService.deleteMaterial(id);
        return success("Material deleted successfully");
    }

    @GetMapping("/get/{id}")
    public AjaxResult getMaterialById(@PathVariable Integer id) {
        return success(materialService.getMaterialById(id));
    }

    @GetMapping("/list")
    public TableDataInfo getAllMaterials() {
        startPage();
        return getDataTable(materialService.getAllMaterials());
    }
}
